package com.yangyang.ralearn.common.entity.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.yangyang.ralearn.common.types.JObject;

public abstract class BaseAction implements Cloneable, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4927894186542097502L;
	protected String type;
	protected List<JObject> paramValues;

	public BaseAction(String type, JObject... paramValues) {
		this.setType(type);
		this.paramValues = new ArrayList<JObject>();
		if (paramValues != null)
			for (JObject object : paramValues) {
				this.paramValues.add(object);
			}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<JObject> getValues() {
		return this.paramValues;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof BaseAction))
			return false;
		BaseAction action = (BaseAction) obj;
		if (action.type.equals(this.type)
				&& action.paramValues.size() == this.paramValues.size()) {
			// for (JObject object : action.paramValues) {
			// if (!this.paramValues.contains(object))
			// return false;
			// }
			// return true;
			for (int i = 0; i < action.paramValues.size(); i++) {
				if (!action.paramValues.get(i).equals(this.paramValues.get(i)))
					return false;
			}
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return this.type.hashCode();
	}

	@Override
	public abstract BaseAction clone();

	@Override
	public String toString() {
		// return "BaseActionDef [type=" + type + ", paramValues=" + paramValues
		// + "]";
		StringBuilder sb = new StringBuilder(this.type);
		for (JObject value : paramValues)
			sb.append(" " + value.getName());
		return sb.toString();
	}

}
